home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / MenuFrame2 / Item.class (.txt) next >
Encoding:
Java Class File  |  2001-11-06  |  5.3 KB  |  192 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Cursor;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Label;
  8. import java.awt.MenuItem;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseListener;
  11. import java.awt.event.MouseMotionListener;
  12. import java.net.URL;
  13.  
  14. class Item extends Label implements MouseListener, MouseMotionListener {
  15.    // $FF: renamed from: mf MenuFrame2
  16.    MenuFrame2 field_0;
  17.    String link;
  18.    String statusText;
  19.    Color textColor;
  20.    Color enterTextColor;
  21.    Color backColor;
  22.    Color enterBackColor;
  23.    Color borderColor;
  24.    int borderSize;
  25.    boolean isActive;
  26.    boolean topItem;
  27.    boolean hasChildren = false;
  28.    MenuItem menuitem;
  29.  
  30.    public Item() {
  31.    }
  32.  
  33.    public Item(String label, MenuFrame2 mf, String link, Color textColor, Color backColor, Color enterTextColor, Color enterBackColor, Color borderColor, int borderSize, boolean isActive) {
  34.       super(" " + label + " ");
  35.       this.field_0 = mf;
  36.       this.link = link;
  37.       this.textColor = textColor;
  38.       this.backColor = backColor;
  39.       this.enterTextColor = enterTextColor;
  40.       this.enterBackColor = enterBackColor;
  41.       this.borderSize = borderSize;
  42.       this.borderColor = borderColor;
  43.       this.isActive = isActive;
  44.       Font f = ((Component)this).getFont();
  45.       String fontName = ((Applet)mf).getParameter("item_font_name");
  46.       if (fontName == null) {
  47.          fontName = f.getName();
  48.       }
  49.  
  50.       String s = ((Applet)mf).getParameter("item_font_height");
  51.       int textHeight;
  52.       if (s != null) {
  53.          textHeight = Integer.parseInt(s);
  54.       } else {
  55.          textHeight = 12;
  56.       }
  57.  
  58.       int style = 0;
  59.       s = ((Applet)mf).getParameter("item_font_style");
  60.       if (s != null) {
  61.          if (s.equals("bold")) {
  62.             style = 1;
  63.          } else if (s.equals("italic")) {
  64.             style = 2;
  65.          } else if (s.equals("bold_italic")) {
  66.             style = 3;
  67.          } else {
  68.             style = 0;
  69.          }
  70.       }
  71.  
  72.       Font normalFont;
  73.       try {
  74.          normalFont = new Font(fontName, style, textHeight);
  75.       } catch (Exception var17) {
  76.          normalFont = new Font(f.getName(), style, textHeight);
  77.       }
  78.  
  79.       ((Component)this).setFont(normalFont);
  80.       ((Component)this).addMouseListener(this);
  81.       ((Component)this).addMouseMotionListener(this);
  82.       ((Component)this).setBackground(backColor);
  83.       ((Component)this).setForeground(textColor);
  84.       ((Label)this).setAlignment(1);
  85.       if (!isActive) {
  86.          ((Component)this).setVisible(false);
  87.       }
  88.  
  89.       ((Component)this).repaint();
  90.    }
  91.  
  92.    public void update(Graphics g) {
  93.       this.paint(g);
  94.    }
  95.  
  96.    public void paint(Graphics g) {
  97.       int wi = ((Component)this).getSize().width;
  98.       int he = ((Component)this).getSize().height;
  99.       if (this.borderSize > 0) {
  100.          g.setColor(this.borderColor);
  101.  
  102.          for(int i = 0; i < this.borderSize; ++i) {
  103.             g.drawRect(i, i, wi - 2 * i - 1, he - 2 * i - 1);
  104.          }
  105.       }
  106.  
  107.       if (this.hasChildren) {
  108.          g.setColor(((Component)this).getForeground());
  109.          int height = ((Component)this).getSize().height;
  110.          int width = ((Component)this).getSize().width;
  111.          float h = (float)height / 5.0F;
  112.          int l = (int)(Math.sqrt((double)3.0F) / (double)2.0F * (double)h);
  113.          int x1 = width - 3 - this.borderSize - l;
  114.          int x2 = width - 3 - this.borderSize;
  115.          int y1 = (int)((double)((float)height) / (double)2.0F - (double)(h / 2.0F));
  116.          int y2 = height / 2;
  117.          int y3 = (int)((double)((float)height) / (double)2.0F + (double)(h / 2.0F));
  118.          int X = 0;
  119.  
  120.          while(true) {
  121.             g.drawLine(x1 + X, y1 + X, x1 + X, y3 - X);
  122.             g.drawLine(x1 + X, y1 + X, x2 - X, y2);
  123.             g.drawLine(x1 + X, y3 - X, x2 - X, y2);
  124.             if (x1 + X >= x2 - X) {
  125.                break;
  126.             }
  127.  
  128.             ++X;
  129.          }
  130.       }
  131.  
  132.    }
  133.  
  134.    public void mouseClicked(MouseEvent e) {
  135.    }
  136.  
  137.    public void mouseEntered(MouseEvent e) {
  138.       if (this.topItem && this.field_0.isActive) {
  139.          this.field_0.showFirstChildren(this.menuitem);
  140.       } else if (!this.topItem) {
  141.          this.field_0.showChildren(this.menuitem);
  142.       }
  143.  
  144.       ((Component)this).setForeground(this.enterTextColor);
  145.       ((Component)this).setBackground(this.enterBackColor);
  146.       if (this.field_0.hand && !((Label)this).getText().equals("")) {
  147.          ((Component)this).setCursor(Cursor.getPredefinedCursor(12));
  148.       }
  149.  
  150.       ((Component)this).repaint();
  151.    }
  152.  
  153.    public void mouseExited(MouseEvent e) {
  154.       ((Component)this).setForeground(this.textColor);
  155.       ((Component)this).setBackground(this.backColor);
  156.       if (this.field_0.hand) {
  157.          ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
  158.       }
  159.  
  160.       ((Component)this).repaint();
  161.    }
  162.  
  163.    public void mousePressed(MouseEvent e) {
  164.    }
  165.  
  166.    public void mouseReleased(MouseEvent e) {
  167.       if (this.topItem) {
  168.          this.field_0.showFirstChildren(this.menuitem);
  169.       }
  170.  
  171.       if (!this.topItem && !this.hasChildren) {
  172.          if (this.field_0.clicSound != null) {
  173.             this.field_0.clicSound.play();
  174.          }
  175.  
  176.          URL u = this.field_0.giveURL(this.link);
  177.          String target = this.field_0.getParameter("target");
  178.          if (target == null) {
  179.             target = "_blank";
  180.          }
  181.  
  182.          this.field_0.getAppletContext().showDocument(u, target);
  183.       }
  184.    }
  185.  
  186.    public void mouseDragged(MouseEvent e) {
  187.    }
  188.  
  189.    public void mouseMoved(MouseEvent e) {
  190.    }
  191. }
  192.